package qsou.rpc.web.exampleserver;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import qsou.rpc.framework.annotation.RpcScan;
import qsou.rpc.framework.config.RpcServiceConfig;
import qsou.rpc.framework.remoting.transport.netty.server.NettyRpcServer;
import qsou.rpc.service.hello.HelloService;
import qsou.rpc.web.exampleserver.serviceimpl.HelloServiceImpl2;

/**
 * @description:
 * @auther: wuxw
 * @Date: 2022/3/30 16:07
 */
@RpcScan(basePackage = {"qsou.rpc"})
public class NettyServerMain {
  public static void main(String[] args) {
    // Register service via annotation
    AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(NettyServerMain.class);
    NettyRpcServer nettyRpcServer = (NettyRpcServer) applicationContext.getBean("nettyRpcServer");
    // Register service manually
    HelloService helloService2 = new HelloServiceImpl2();
    RpcServiceConfig rpcServiceConfig = RpcServiceConfig.builder()
        .group("test2").version("version2").service(helloService2).build();
    nettyRpcServer.registerService(rpcServiceConfig);
    nettyRpcServer.start();
  }
}